﻿using GameEntitySystem;
using TemplatesDatabase;

namespace Game
{
    public class SubsystemCommandExt : Subsystem, IUpdateable
    {
        public Dictionary<string, Dictionary<string, object>> m_creatureDataChange = new Dictionary<string, Dictionary<string, object>>();

        public Dictionary<int, SubsystemBlockBehavior[]> m_originBehaviorsById = new Dictionary<int, SubsystemBlockBehavior[]>();

        public SubsystemCommand subsystemCommand;

        public SubsystemBodies subsystemBodies;

        public static bool BlockDataChange = false;

        public static bool ClothesDataChange = false;

        public static Action LoadAction;

        public UpdateOrder UpdateOrder => UpdateOrder.Default;

        public void Update(float dt)
        {
        }

        public override void OnEntityAdded(Entity entity)
        {
            if (m_creatureDataChange.Count <= 0) return;
            foreach (string name in m_creatureDataChange.Keys)
            {
                if (name == entity.ValuesDictionary.DatabaseObject.Name.ToLower())
                {
                    ComponentCreature creature = entity.FindComponent<ComponentCreature>();
                    foreach (string type in m_creatureDataChange[name].Keys)
                    {
                        object value = m_creatureDataChange[name][type];
                        switch (type)
                        {
                            case "box-size": creature.ComponentBody.BoxSize = (Vector3)value / 10f; break;
                            case "air-drag": creature.ComponentBody.AirDrag = (Vector2)value / 10f; break;
                            case "water-drag": creature.ComponentBody.WaterDrag = (Vector2)value / 10f; break;
                            case "mass": creature.ComponentBody.Mass = (int)value / 10f; break;
                            case "density": creature.ComponentBody.Density = (int)value; break;
                            case "air-capacity": creature.ComponentHealth.AirCapacity = (int)value; break;
                            case "health": creature.ComponentHealth.Health = (int)value / 100f; break;
                            case "attack-power": creature.Entity.FindComponent<ComponentMiner>(true).AttackPower = (int)value; break;
                            case "attack-resilience": creature.ComponentHealth.AttackResilience = (int)value / 10f; break;
                            case "fall-resilience": creature.ComponentHealth.FallResilience = (int)value / 10f; break;
                            case "corpse-duration": creature.ComponentHealth.CorpseDuration = (int)value / 10f; break;
                            case "stun-time": creature.ComponentLocomotion.StunTime = (int)value / 10f; break;
                            case "jump-order": creature.ComponentLocomotion.JumpOrder = (int)value / 10f; break;
                            case "jump-speed": creature.ComponentLocomotion.JumpSpeed = (int)value / 10f; break;
                            case "swim-speed": creature.ComponentLocomotion.SwimSpeed = (int)value / 10f; break;
                            case "turn-speed": creature.ComponentLocomotion.TurnSpeed = (int)value / 10f; break;
                            case "walk-speed": creature.ComponentLocomotion.WalkSpeed = (int)value / 10f; break;
                            case "fly-speed": creature.ComponentLocomotion.FlySpeed = (int)value / 10f; break;
                            case "is-invulnerable": creature.ComponentHealth.IsInvulnerable = (bool)value; break;
                        }
                    }
                    break;
                }
            }
        }

        public override void Load(ValuesDictionary valuesDictionary)
        {
            subsystemCommand = Project.FindSubsystem<SubsystemCommand>();
            subsystemBodies = Project.FindSubsystem<SubsystemBodies>();
            m_originBehaviorsById.Clear();
            if (BlockDataChange)
            {
                foreach (ModEntity modEntity in ModsManager.ModList)
                {
                    modEntity.LoadBlocksData();
                }
                BlockDataChange = false;
            }
            if (ClothesDataChange)
            {
                ((ClothingBlock)(BlocksManager.Blocks[203])).Initialize();
                ClothesDataChange = false;
            }
			SubsystemCommand.AddFunction("blockdata", delegate (CommandData commandData)
            {
                BlockDataChange = true;
                return ChangeBlockData(commandData);
            });
			SubsystemCommand.AddFunction("creaturedata", delegate (CommandData commandData)
            {
                SubmitResult submitResult = ChangeCreatureData(commandData);
                if (submitResult == SubmitResult.Success && commandData.Type != "default")
                {
                    object value = null;
                    object vec3 = commandData.GetValue("vec3");
                    object vec2 = commandData.GetValue("vec2");
                    object v = commandData.GetValue("v");
                    object con = commandData.GetValue("con");
                    if (vec3 != null) value = vec3;
                    else if (vec2 != null) value = vec2;
                    else if (v != null) value = v;
                    else if (con != null) value = con;
                    string[] types = {
                        "box-size", "air-drag", "water-drag", "mass", "density", "air-capacity", "health",
                        "attack-power", "attack-resilience", "fall-resilience", "corpse-duration", "stun-time",
                        "jump-order", "jump-speed", "swim-speed", "turn-speed", "walk-speed", "fly-speed"
                    };
                    foreach (string type in types)
                    {
                        if (type == commandData.Type)
                        {
                            string obj = (string)commandData.GetValue("obj");
                            if (!m_creatureDataChange.ContainsKey(obj))
                            {
                                m_creatureDataChange[obj] = new Dictionary<string, object>();
                            }
                            m_creatureDataChange[obj][type] = value;
                            break;
                        }
                    }
                }
                return submitResult;
            });
			SubsystemCommand.AddFunction("clothesdata", delegate (CommandData commandData)
            {
                ClothesDataChange = true;
                return ChangeClothesdata(commandData);
            });
            if (LoadAction != null)
            {
                LoadAction.Invoke();
            }
        }

        public SubmitResult ChangeBlockData(CommandData commandData)
        {
            if (commandData.Type == "default")
            {
                return SubmitResult.Success;
            }
            int id = (int)commandData.GetValue("id");
            Block block = BlocksManager.Blocks[id];
            if (block is AirBlock)
            {
                subsystemCommand.ShowSubmitTips("无效的方块id:" + id);
                return SubmitResult.Fail;
            }
            if (commandData.Type == "behaviors")
            {
                string opt = (string)commandData.GetValue("opt");
                try
                {
                    if (opt.ToLower() == "null")
                    {
                        if (m_originBehaviorsById.TryGetValue(id, out SubsystemBlockBehavior[] originValue))
                        {
                            Project.FindSubsystem<SubsystemBlockBehaviors>().m_blockBehaviorsByContents[id] = m_originBehaviorsById[id];
                        }
                        return SubmitResult.Success;
                    }
                    bool exist = false;
                    string[] availBehaviors = {"Throwable","Wood","Ivy","Rot","BottomSucker","WaterPlant","Fence","ImpactExplosives", "Explosives","Carpet" ,"Campfile","Furniture","Egg",
                                "Hammer","Bow","Crossbow","Musket","Arrow","Bomb","Fireworks","Piston","Grave","Soil","Saddle","Match","Bucket","Cactus","Bullet","Fertilizer"};
                    string[] behaviors = opt.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    for (int i = 0; i < behaviors.Length; i++)
                    {
                        foreach (string s in availBehaviors)
                        {
                            if (s.ToLower() == behaviors[i].ToLower())
                            {
                                behaviors[i] = s + "BlockBehavior";
                                exist = true;
                                break;
                            }
                        }
                        if (!exist)
                        {
                            subsystemCommand.ShowSubmitTips(string.Format("{0}行为不存在或不可用", behaviors[i]));
                            return SubmitResult.Fail;
                        }
                        exist = false;
                    }
                    List<SubsystemBlockBehavior> behaviorList = new List<SubsystemBlockBehavior>();
                    foreach (string b in behaviors)
                    {
                        SubsystemBlockBehavior item = Project.FindSubsystem<SubsystemBlockBehavior>(b.Trim(), throwOnError: true);
                        behaviorList.Add(item);
                    }
                    if (!m_originBehaviorsById.TryGetValue(id, out SubsystemBlockBehavior[] value))
                    {
                        value = Project.FindSubsystem<SubsystemBlockBehaviors>().m_blockBehaviorsByContents[id];
                        m_originBehaviorsById[id] = value;
                    }
                    foreach (SubsystemBlockBehavior item in value)
                    {
                        behaviorList.Add(item);
                    }
                    Project.FindSubsystem<SubsystemBlockBehaviors>().m_blockBehaviorsByContents[id] = behaviorList.ToArray();
                }
                catch
                {
                    Log.Warning("The illegal behaviors");
                    subsystemCommand.ShowSubmitTips("行为装载发生了未知错误");
                    return SubmitResult.Fail;
                }
            }
            else if (commandData.Type == "food-type")
            {
                string opt = (string)commandData.GetValue("opt");
                switch (opt.ToLower())
                {
                    case "bread": BlocksManager.Blocks[id].FoodType = FoodType.Bread; break;
                    case "fish": BlocksManager.Blocks[id].FoodType = FoodType.Fish; break;
                    case "fruit": BlocksManager.Blocks[id].FoodType = FoodType.Fruit; break;
                    case "grass": BlocksManager.Blocks[id].FoodType = FoodType.Grass; break;
                    case "meat": BlocksManager.Blocks[id].FoodType = FoodType.Meat; break;
                    case "null": BlocksManager.Blocks[id].FoodType = FoodType.None; break;
                    default: subsystemCommand.ShowSubmitTips("不存在食物类型:" + opt); return SubmitResult.Fail;
                }
            }
            else
            {
                object con = commandData.GetValue("con");
                if (con != null)
                {
                    bool flag = (bool)con;
                    switch (commandData.Type)
                    {
                        case "is-collidable": BlocksManager.Blocks[id].IsCollidable = flag; break;
                        case "is-placeable": BlocksManager.Blocks[id].IsPlaceable = flag; break;
                        case "is-digging-transparent": BlocksManager.Blocks[id].IsDiggingTransparent = flag; break;
                        case "is-placement-transparent": BlocksManager.Blocks[id].IsPlacementTransparent = flag; break;
                        case "is-interactive": BlocksManager.Blocks[id].DefaultIsInteractive = flag; break;
                        case "is-editable": BlocksManager.Blocks[id].IsEditable = flag; break;
                        case "is-non-duplicable": BlocksManager.Blocks[id].IsNonDuplicable = flag; break;
                        case "is-gatherable": BlocksManager.Blocks[id].IsGatherable = flag; break;
                        case "has-collision-behavior": BlocksManager.Blocks[id].HasCollisionBehavior = flag; break;
                        case "kills-when-stuck": BlocksManager.Blocks[id].KillsWhenStuck = flag; break;
                        case "is-fluid-blocker": BlocksManager.Blocks[id].IsFluidBlocker = flag; break;
                        case "is-transparent": BlocksManager.Blocks[id].IsTransparent = flag; break;
                        case "is-aimable": BlocksManager.Blocks[id].IsAimable = flag; break;
                        case "is-stickable": BlocksManager.Blocks[id].IsStickable = flag; break;
                        case "align-to-velocity": BlocksManager.Blocks[id].AlignToVelocity = flag; break;
                        case "no-auto-jump": BlocksManager.Blocks[id].NoAutoJump = flag; break;
                        case "no-smooth-rise": BlocksManager.Blocks[id].NoSmoothRise = flag; break;
                        case "disintegrates-on-hit": BlocksManager.Blocks[id].DisintegratesOnHit = flag; break;
                        case "explosion-incendiary": BlocksManager.Blocks[id].DefaultExplosionIncendiary = flag; break;
                        case "is-explosion-transparent": BlocksManager.Blocks[id].IsExplosionTransparent = flag; break;
                        default: return SubmitResult.Fail;
                    }
                    return SubmitResult.Success;
                }
                object v = commandData.GetValue("v");
                if (v != null)
                {
                    int ivalue = (int)v;
                    float fvalue = ivalue / 10f;
                    switch (commandData.Type)
                    {
                        case "icon-view-scale": BlocksManager.Blocks[id].DefaultIconViewScale = fvalue; break;
                        case "first-person-scale": BlocksManager.Blocks[id].FirstPersonScale = fvalue; break;
                        case "in-hand-scale": BlocksManager.Blocks[id].InHandScale = fvalue; break;
                        case "shadow-strength": BlocksManager.Blocks[id].DefaultShadowStrength = ivalue; break;
                        case "light-attenuation": BlocksManager.Blocks[id].LightAttenuation = ivalue; break;
                        case "emitted-light-amount": BlocksManager.Blocks[id].DefaultEmittedLightAmount = ivalue; break;
                        case "object-shadow-strength": BlocksManager.Blocks[id].ObjectShadowStrength = fvalue; break;
                        case "drop-count": BlocksManager.Blocks[id].DefaultDropCount = ivalue; break;
                        case "experience-count": BlocksManager.Blocks[id].DefaultExperienceCount = fvalue; break;
                        case "required-tool-level": BlocksManager.Blocks[id].RequiredToolLevel = ivalue; break;
                        case "max-stacking": BlocksManager.Blocks[id].MaxStacking = ivalue; break;
                        case "sleep-suitability": BlocksManager.Blocks[id].SleepSuitability = fvalue; break;
                        case "friction-factor": BlocksManager.Blocks[id].FrictionFactor = fvalue; break;
                        case "density": BlocksManager.Blocks[id].Density = fvalue; break;
                        case "fuel-heat-level": BlocksManager.Blocks[id].FuelHeatLevel = ivalue; break;
                        case "fuel-fire-duration": BlocksManager.Blocks[id].FuelFireDuration = ivalue; break;
                        case "shovel-power": BlocksManager.Blocks[id].ShovelPower = fvalue; break;
                        case "quarry-power": BlocksManager.Blocks[id].QuarryPower = fvalue; break;
                        case "hack-power": BlocksManager.Blocks[id].HackPower = fvalue; break;
                        case "melee-power": BlocksManager.Blocks[id].DefaultMeleePower = fvalue; break;
                        case "melee-hit-probability": BlocksManager.Blocks[id].DefaultMeleeHitProbability = fvalue; break;
                        case "projectile-power": BlocksManager.Blocks[id].DefaultProjectilePower = fvalue; break;
                        case "tool-level": BlocksManager.Blocks[id].ToolLevel = ivalue; break;
                        case "player-level-required": BlocksManager.Blocks[id].PlayerLevelRequired = ivalue; break;
                        case "projectile-speed": BlocksManager.Blocks[id].ProjectileSpeed = ivalue; break;
                        case "projectile-damping": BlocksManager.Blocks[id].ProjectileDamping = fvalue; break;
                        case "projectile-tip-offset": BlocksManager.Blocks[id].ProjectileTipOffset = fvalue; break;
                        case "projectile-stick-probability": BlocksManager.Blocks[id].ProjectileStickProbability = fvalue; break;
                        case "heat": BlocksManager.Blocks[id].DefaultHeat = fvalue; break;
                        case "fire-duration": BlocksManager.Blocks[id].FireDuration = ivalue; break;
                        case "explosion-resilience": BlocksManager.Blocks[id].ExplosionResilience = ivalue; break;
                        case "explosion-pressure": BlocksManager.Blocks[id].DefaultExplosionPressure = ivalue; break;
                        case "dig-resilience": BlocksManager.Blocks[id].DigResilience = fvalue; break;
                        case "projectile-resilience": BlocksManager.Blocks[id].ProjectileResilience = fvalue; break;
                        case "sickness-probability": BlocksManager.Blocks[id].DefaultSicknessProbability = fvalue; break;
                        case "rot-period": BlocksManager.Blocks[id].DefaultRotPeriod = ivalue; break;
                        case "texture-slot": BlocksManager.Blocks[id].DefaultTextureSlot = ivalue; break;
                        case "drop-content": BlocksManager.Blocks[id].DefaultDropContent = ivalue; break;
                        case "durability": BlocksManager.Blocks[id].Durability = ivalue; break;
                        default: return SubmitResult.Fail;
                    }
                    return SubmitResult.Success;
                }
                object vec3 = commandData.GetValue("vec3");
                if (vec3 != null)
                {
                    Vector3 vector = (Vector3)vec3;
                    switch (commandData.Type)
                    {
                        case "icon-block-offset": BlocksManager.Blocks[id].DefaultIconBlockOffset = vector; break;
                        case "icon-view-offset": BlocksManager.Blocks[id].DefaultIconViewOffset = vector; break;
                        case "first-person-offset": BlocksManager.Blocks[id].FirstPersonOffset = vector; break;
                        case "first-person-rotation": BlocksManager.Blocks[id].FirstPersonRotation = vector; break;
                        case "in-hand-offset": BlocksManager.Blocks[id].InHandOffset = vector; break;
                        case "in-hand-rotation": BlocksManager.Blocks[id].InHandRotation = vector; break;
                        default: return SubmitResult.Fail;
                    }
                    return SubmitResult.Success;
                }
            }
            return SubmitResult.Success;
        }

        public SubmitResult ChangeCreatureData(CommandData commandData)
        {
            if (commandData.Type == "default")
            {
                return SubmitResult.Success;
            }
            string obj = (string)commandData.GetValue("obj");
            Vector2 playerPos = new Vector2(subsystemCommand.m_componentPlayer.ComponentBody.Position.X, subsystemCommand.m_componentPlayer.ComponentBody.Position.Z);
            DynamicArray<ComponentBody> targetArray = new DynamicArray<ComponentBody>();
            subsystemBodies.FindBodiesInArea(playerPos - new Vector2(64f), playerPos + new Vector2(64f), targetArray);
            foreach (ComponentBody body in targetArray)
            {
                bool isPlayer = (body.Entity.FindComponent<ComponentPlayer>() != null && obj == "player");
                if (obj == body.Entity.ValuesDictionary.DatabaseObject.Name.ToLower() || isPlayer)
                {
                    ComponentDamage damage = body.Entity.FindComponent<ComponentDamage>();
                    if (damage != null)
                    {
                        subsystemCommand.ShowSubmitTips("creaturedata指令暂时不支持载具");
                        return SubmitResult.Fail;
                    }
                    ComponentCreature creature = body.Entity.FindComponent<ComponentCreature>();
                    if (creature != null)
                    {
                        if (commandData.Type.StartsWith("action-"))
                        {
                            int v = (int)commandData.GetValue("v");
                            float range = v / 10f;
                            ComponentCreatureModel creatureModel = creature.ComponentCreatureModel;
                            if (creatureModel is ComponentFourLeggedModel)
                            {
                                switch (commandData.Type)
                                {
                                    case "action-head": ((ComponentFourLeggedModel)creatureModel).m_headAngleY = range; break;
                                    case "action-left-hand": ((ComponentFourLeggedModel)creatureModel).m_legAngle1 = range; break;
                                    case "action-right-hand": ((ComponentFourLeggedModel)creatureModel).m_legAngle2 = range; break;
                                    case "action-left-leg": ((ComponentFourLeggedModel)creatureModel).m_legAngle3 = range; break;
                                    case "action-right-leg": ((ComponentFourLeggedModel)creatureModel).m_legAngle4 = range; break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                            else if (creatureModel is ComponentFlightlessBirdModel)
                            {
                                switch (commandData.Type)
                                {
                                    case "action-head": ((ComponentFlightlessBirdModel)creatureModel).m_headAngleY = range; break;
                                    case "action-left-hand": ((ComponentFlightlessBirdModel)creatureModel).m_legAngle1 = range; break;
                                    case "action-right-hand": ((ComponentFlightlessBirdModel)creatureModel).m_legAngle2 = range; break;
                                    case "action-left-leg": ((ComponentFlightlessBirdModel)creatureModel).m_legAngle1 = range; break;
                                    case "action-right-leg": ((ComponentFlightlessBirdModel)creatureModel).m_legAngle2 = range; break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                            else if (creatureModel is ComponentHumanModel)
                            {
                                switch (commandData.Type)
                                {
                                    case "action-head": ((ComponentHumanModel)creatureModel).m_headAngles = new Vector2(0, range); break;
                                    case "action-left-hand": ((ComponentHumanModel)creatureModel).m_handAngles1 = new Vector2(range, -range * 0.1f); break;
                                    case "action-right-hand": ((ComponentHumanModel)creatureModel).m_handAngles2 = new Vector2(range, range * 0.1f); break;
                                    case "action-left-leg": ((ComponentHumanModel)creatureModel).m_legAngles1 = new Vector2(range, range * 0.1f); break;
                                    case "action-right-leg": ((ComponentHumanModel)creatureModel).m_legAngles2 = new Vector2(range, -range * 0.1f); break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                            else if (creatureModel is ComponentBirdModel)
                            {
                                subsystemCommand.ShowSubmitTips("当前指令暂不支持鸟模型");
                                return SubmitResult.Fail;
                            }
                            else if (creatureModel is ComponentFishModel)
                            {
                                subsystemCommand.ShowSubmitTips("当前指令暂不支持鱼模型");
                                return SubmitResult.Fail;
                            }
                        }
                        else
                        {
                            object vec3 = commandData.GetValue("vec3");
                            if (vec3 != null)
                            {
                                Vector3 vector = (Vector3)vec3 / 10f;
                                switch (commandData.Type)
                                {
                                    case "box-size": creature.ComponentBody.BoxSize = vector; break;
                                    case "velocity": creature.ComponentBody.Velocity = vector; break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                            object vec2 = commandData.GetValue("vec2");
                            if (vec2 != null)
                            {
                                Vector2 vector = (Vector2)vec2 / 10f;
                                switch (commandData.Type)
                                {
                                    case "look-order": creature.ComponentLocomotion.LookOrder = vector; break;
                                    case "turn-order": creature.ComponentLocomotion.TurnOrder = vector; break;
                                    case "air-drag": creature.ComponentBody.AirDrag = vector; break;
                                    case "water-drag": creature.ComponentBody.WaterDrag = vector; break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                            object v = commandData.GetValue("v");
                            if (v != null)
                            {
                                int ivalue = (int)v;
                                float fvalue = ivalue / 10f;
                                switch (commandData.Type)
                                {
                                    case "mass": creature.ComponentBody.Mass = fvalue; break;
                                    case "density": creature.ComponentBody.Density = ivalue; break;
                                    case "air-capacity": creature.ComponentHealth.AirCapacity = ivalue; break;
                                    case "health": creature.ComponentHealth.Health = ivalue / 100f; break;
                                    case "attack-power": creature.Entity.FindComponent<ComponentMiner>(true).AttackPower = ivalue; break;
                                    case "attack-resilience": creature.ComponentHealth.AttackResilience = fvalue; break;
                                    case "fall-resilience": creature.ComponentHealth.FallResilience = fvalue; break;
                                    case "corpse-duration": creature.ComponentHealth.CorpseDuration = fvalue; break;
                                    case "stun-time": creature.ComponentLocomotion.StunTime = fvalue; break;
                                    case "jump-order": creature.ComponentLocomotion.JumpOrder = fvalue; break;
                                    case "jump-speed": creature.ComponentLocomotion.JumpSpeed = fvalue; break;
                                    case "swim-speed": creature.ComponentLocomotion.SwimSpeed = fvalue; break;
                                    case "turn-speed": creature.ComponentLocomotion.TurnSpeed = fvalue; break;
                                    case "walk-speed": creature.ComponentLocomotion.WalkSpeed = fvalue; break;
                                    case "fly-speed": creature.ComponentLocomotion.FlySpeed = fvalue; break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                            object con = commandData.GetValue("con");
                            if (con != null)
                            {
                                bool flag = (bool)con;
                                switch (commandData.Type)
                                {
                                    case "is-invulnerable": creature.ComponentHealth.IsInvulnerable = flag; break;
                                    default: return SubmitResult.Fail;
                                }
                            }
                        }
                    }
                }
            }
            return SubmitResult.Success;
        }

        public SubmitResult ChangeClothesdata(CommandData commandData)
        {
            if (commandData.Type == "default")
            {
                return SubmitResult.Success;
            }
            int cid = (int)commandData.GetValue("cid");
            ClothingBlock clothingBlock = (ClothingBlock)BlocksManager.Blocks[203];
            if (cid > clothingBlock.m_clothingData.Count - 1)
            {
                subsystemCommand.ShowSubmitTips(string.Format("衣服序号的范围是:{0}-{1}", 0, clothingBlock.m_clothingData.Count - 1));
                return SubmitResult.Fail;
            }
            object v = commandData.GetValue("v");
            if (v != null)
            {
                int ivalue = (int)v;
                float fvalue = ivalue / 10f;
                switch (commandData.Type)
                {
                    case "armor-protection": clothingBlock.m_clothingData[cid].ArmorProtection = fvalue; break;
                    case "sturdiness": clothingBlock.m_clothingData[cid].Sturdiness = ivalue; break;
                    case "insulation": clothingBlock.m_clothingData[cid].Insulation = fvalue; break;
                    case "movement-speed-factor": clothingBlock.m_clothingData[cid].MovementSpeedFactor = fvalue; break;
                    case "steed-movement-speed-factor": clothingBlock.m_clothingData[cid].SteedMovementSpeedFactor = fvalue; break;
                    case "density-modifier": clothingBlock.m_clothingData[cid].DensityModifier = fvalue; break;
                    case "layer": clothingBlock.m_clothingData[cid].Layer = ivalue; break;
                    case "player-level-required": clothingBlock.m_clothingData[cid].PlayerLevelRequired = ivalue; break;
                    default: return SubmitResult.Fail;
                }
            }
            object con = commandData.GetValue("con");
            if (con != null)
            {
                bool flag = (bool)con;
                switch (commandData.Type)
                {
                    case "is-outer": clothingBlock.m_clothingData[cid].IsOuter = flag; break;
                    case "can-be-dyed": clothingBlock.m_clothingData[cid].CanBeDyed = flag; break;
                    default: return SubmitResult.Fail;
                }
            }
            return SubmitResult.Success;
        }
    }
}
